﻿#region Usings

using System;
using System.Web.Security;

#endregion

namespace XPressify.Data
{
    public partial class User
    {
        public override string FullName
        {
            get { return String.Join(" ", new[] {FirstName, LastName}); }
        }

        public static User CreateFromTicket(FormsAuthenticationTicket ticket)
        {
            var tokens = ticket.UserData.Split(',');
            var user = new User
                           {
                               FirstName = tokens[0],
                               LastName = tokens[1],
                               Email = tokens[2],
                               Username = tokens[3],
                               Role = tokens[4]
                           };
            return user;
        }

        public string SerializeForTicket()
        {
            return String.Format("{0},{1},{2},{3},{4}",
                                 FirstName,
                                 LastName,
                                 Email,
                                 Username,
                                 Role);
        }
    }
}